

// 重置
$('body').on('click', '#reset-filter-btn', function() {
  $(this).parents('.filter-detail').find('input').val('');
});


var Batchwithdrawal = $('#Batchwithdrawal'),
    deletion = $('#deletion'),
    status,
    selectId,
    sumId = [],
    operate;

    Batchwithdrawal.on('click',function(){
		if ($('.check-one:checked').length > 0) {
			$.each($('.check-one:checked'),function(i,val){
				selectId = $(val).data('id');
				if (sumId.indexOf(selectId) == -1 && sumId.length > 1) {
					sumId.push(selectId);
				}else if (sumId.indexOf(selectId) == -1 && sumId.length <= 1){
					sumId.push(selectId);
				}
			})
			console.log(sumId)
			$.ajax({
	    		url:'/Admin/Information/News/batchChangeNewsStatus',
	    		type:'post',
	    		data:{ids:sumId,operate:1,status:2},
	    		dataType:'json',
	    		success:function(json){
	    			console.log(json)
	    			if (json.code == 1) {
	    				$.alert('批量撤稿成功！');
	    				setTimeout(function(){
	    					window.location.reload();
	    				},1500);
	    			}else{
	    				$.alert(json.msg);
	    			}
	    		},
	    		error:function(json){

	    		}
	    	})
			
		}else{
			$.alert('请至少选择一条！')
    		return false;
		}
    	
    	
    })

    deletion.on('click',function(){
    	console.log($('.check-one:checked').length)
		if ($('.check-one:checked').length > 0) {
			$.each($('.check-one:checked'),function(i,val){
				selectId = $(val).data('id');
				if (sumId.indexOf(selectId) == -1 && sumId.length > 1) {
					sumId.push(selectId);
				}else if (sumId.indexOf(selectId) == -1 && sumId.length <= 1){
					sumId.push(selectId);
				}
			})
		 	$.ajax({
	    		url:'/Admin/Information/News/batchChangeNewsStatus',
	    		type:'post',
	    		data:{ids:sumId,operate:2,status:0},
	    		dataType:'json',
	    		success:function(json){
	    			console.log(json)
		    			if (json.code == 1) {
		    				$.alert('批量删除成功！');
		    				setTimeout(function(){
		    					window.location.reload();
		    				},1500);
		    			}else{
		    				$.alert(json.msg);
		    			}
	    		},
	    		error:function(json){

	    		}
	    	})
			
		}else{
			$.alert('请至少选择一条！');
    		return false;
		}
    	

    })


    // 单个删除

   $('.delete').on('click',function(){
   	var str = '确认删除！';
   	var id = $(this).data('id');
   	$.confirm({
   		msg:str,
   		confirm:function(){
			$.ajax({
	    		url:'/Admin/Information/News/changeNewsStatus',
	    		type:'post',
	    		data:{id:id,operate:2,status:0},
	    		dataType:'json',
	    		success:function(json){
	    			console.log(json)
	    			if (json.code == 1) {
	    				$.alert('删除成功！');
	    				window.location.reload();
	    			}
	    		},
	    		error:function(json){

	    		}
	    	})
		}
   	})
   }) 

       // 单个发布

   $('.publish').on('click',function(){
   	var str = '确认发布！';
   	var id = $(this).data('id');
   	var type = $(this).data('type');
   	if (type == 0) {
   		operate = 1;
   		status = 1;
   	}else{
   		operate = 1;
   		status = 3;
   	}
   	$.confirm({
   		msg:str,
   		confirm:function(){
			$.ajax({
	    		url:'/Admin/Information/News/changeNewsStatus',
	    		type:'post',
	    		data:{id:id,operate:operate,status:status},
	    		dataType:'json',
	    		success:function(json){
	    			console.log(json)
	    			if (json.code == 1) {
	    				$.alert('发布成功！');
	    				window.location.reload();
	    			}
	    		},
	    		error:function(json){

	    		}
	    	})
		}
   	})
   }) 

          // 单个撤稿

   $('.withdrawal').on('click',function(){
   	var str = '确认撤稿！';
   	var id = $(this).data('id');
   	$.confirm({
   		msg:str,
   		confirm:function(){
			$.ajax({
	    		url:'/Admin/Information/News/changeNewsStatus',
	    		type:'post',
	    		data:{id:id,operate:1,status:2},
	    		dataType:'json',
	    		success:function(json){
	    			console.log(json)
	    			if (json.code == 1) {
	    				$.alert('撤稿成功！');
	    				window.location.reload();
	    			}
	    		},
	    		error:function(json){

	    		}
	    	})
		}
   	})
   }) 